package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/*使用预编译sql执行delete语句
需求：根据ID删除userinfo表中的记录
 */
public class JDBCDemo09 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection()){
            String sql = "DELETE FROM userinfo " +
                         "WHERE id=?";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setInt(1,4);
            int i = ps.executeUpdate();
            if (i>0){
                System.out.println("删除成功");
            }else {
                System.out.println("删除失败");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
